//
//  LSZPlayImageAndTableViewVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/9/27.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZPlayImageAndTableViewVC.h"
#import "LSZPlayImageAndTableViewVC+LCAVPlay.h"
#import "JKSongsMessStatus.h"
#import "NetworkTool+LCAVPlay.h"

@interface LSZPlayImageAndTableViewVC ()
{
    NSInteger lastClickRow;
}
@end

@implementation LSZPlayImageAndTableViewVC
-(void)viewWillAppear:(BOOL)animated
{
    self.numberPage = 1;
    [self fromData];
    [LCFloatingWindow sharedInstance].hidden = NO;
}
-(void)viewWillDisappear:(BOOL)animated
{
    [LCFloatingWindow sharedInstance].hidden = YES;
    if(self.viewSharePopover.hidden == NO){
        self.viewSharePopover.hidden = YES;
        self.viewLow.hidden = YES;
        self.butCancel.hidden = YES;
        [LCFloatingWindow sharedInstance].hidden = NO  ;
    }
}
-(void)fromData
{
    //首页音频视频歌手
    if([self.typeComeWhere isEqualToString:@"1"]){
        [self ViewTheDataCacheForDetailsOfTheHomeAudio:self.numberPage];
    }
    //每日灵修
    if ([self.typeComeWhere isEqualToString:@"2"]) {
        self.chooseMonth = [NSString stringWithFormat:@"%@月",[LSZSpecialPackaging GetTheCurrentMonth]];
        int a = 0;
        for (int i = 0; i<self.date3Array.count; i++) {
            NSString * string = [NSString stringWithFormat:@"%@月",self.date3Array[i]];
            if ([string isEqualToString:self.chooseMonth]) {
                a = 1;
            }
        }
        if (a == 0) {
             self.chooseMonth = [NSString stringWithFormat:@"%@月",self.date3Array[0]];
        }
        [self QueryDataDailyDevotionalDetails:self.numberPage month: self.chooseMonth];
    }
    //诗歌的分类
    if([self.typeComeWhere isEqualToString:@"3"]){
        [self ViewTheDataCacheForDetailsOfTheHymnPoem:self.numberPage];
    }
}
-(NSMutableArray *)mutAllOriginalArrayData
{
    if (_mutAllOriginalArrayData == nil) {
        _mutAllOriginalArrayData = [[NSMutableArray alloc]init];
    }
    return _mutAllOriginalArrayData;
}
#pragma mark - 赞美诗歌专辑的分类 ____
-(void)ViewTheDataCacheForDetailsOfTheHymnPoem :(NSInteger)page
{
    __weak typeof(self) weakSelf = self;

    NSString * str = [NSString stringWithFormat:@"%@_%@",zanmei_fenlei,self.parentId];
    [LSZCacheHandling initWithfindPlist:str :^(BOOL isOk, NSDictionary * dic) {
        if (isOk == YES) {
            LSZSpecificTypePlayManager * MG  = [[LSZSpecificTypePlayManager alloc]initWithSpecificTypePlayManager:dic strLastImageView:self.strLastImageView];
            
            [weakSelf.mutArrayData removeAllObjects];
            [weakSelf.mutArrayData addObjectsFromArray:MG.mutDataArray];
            
            [weakSelf.mutAllOriginalArrayData removeAllObjects];
            [weakSelf.mutAllOriginalArrayData setArray:MG.historyArrayData];
            NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
            for (NSInteger i = 0; i < weakSelf.mutAllOriginalArrayData.count; i++) {
                LSZSpecificTypePlayMg *audioMg = [LSZSpecificTypePlayMg yy_modelWithJSON:weakSelf.mutAllOriginalArrayData[i]];
                audioMg.image = weakSelf.strLastImageView;
                NSDictionary *json = [audioMg yy_modelToJSONObject];
                [mutableArray addObject:json];
            }//添加专辑图片
            
            NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:mutableArray];
            NSString * strRow = [NSString stringWithFormat:@"2_2_%@",self.lastPageNumberRow];
            if ([distinguishValue isEqualToString:strRow]) {
                LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                _LCPlayer.songs = playlistTest.allSongs;
            }
            
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [weakSelf.tableViewParticulars reloadData];
            }];
        }else{
            [self initWithClassificationPoetry:page];
        }
    }];
}
#pragma mark - 赞美诗歌的分类
-(void)initWithClassificationPoetry :(NSInteger)page
{
     __weak typeof(self) weakSelf = self;
    [LSZRequestResolutionDic initWithClassificationPoetryDetails:[NSString stringWithFormat:@"%ld",(long)page]  type:self.type parentId:self.parentId strLastImageView:self.strLastImageView:^(BOOL isOK, NSString * str, LSZSpecificTypePlayManager * manager) {
        if (isOK == YES)
        {
            if (page == 1) {
                [weakSelf.mutArrayData removeAllObjects];
                [weakSelf.mutArrayData addObjectsFromArray:manager.mutDataArray];
                
                [weakSelf.mutAllOriginalArrayData removeAllObjects];
                [weakSelf.mutAllOriginalArrayData setArray:manager.historyArrayData];
            }
            else{
                [weakSelf.mutArrayData addObjectsFromArray:manager.mutDataArray];
                
                [weakSelf.mutAllOriginalArrayData addObjectsFromArray:manager.historyArrayData];
                
            }
            
            NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
            for (NSInteger i = 0; i < weakSelf.mutAllOriginalArrayData.count; i++) {
                LSZSpecificTypePlayMg *audioMg = [LSZSpecificTypePlayMg yy_modelWithJSON:weakSelf.mutAllOriginalArrayData[i]];
                audioMg.image = weakSelf.strLastImageView;
                NSDictionary *json = [audioMg yy_modelToJSONObject];
                [mutableArray addObject:json];
            }//添加专辑图片
            
            NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:mutableArray];
            NSString * strRow = [NSString stringWithFormat:@"2_2_%@",self.lastPageNumberRow];
            if ([distinguishValue isEqualToString:strRow]) {
                LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                _LCPlayer.songs = playlistTest.allSongs;
            }
            [weakSelf.tableViewParticulars reloadData];
       
        }else{
            [self initAddString:str];
        }}];
}
-(void)initAddString :(NSString *)message
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;//枚举类型不同的效果
    //    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text= [NSString stringWithFormat:@"%@",message];
    [self performSelector:@selector(hiddenMBAction) withObject:nil afterDelay:1.0];
}
-(void)hiddenMBAction
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
#pragma mark  - ----------每日灵修--------------------
#pragma mark - 查询数据
-(void)QueryDataDailyDevotionalDetails :(NSInteger)page month:(NSString *)month
{
    __weak typeof(self) weakSelf = self;
    NSString * strName = [NSString stringWithFormat:@"%@_%@_%@",lingxiu,weakSelf.parentId,month];
    [LSZCacheHandling initWithfindPlist:strName :^(BOOL isOk, NSDictionary * dic) {
        if (isOk == YES) {
            LSZSpiritualityManager * PoetryMg = [[LSZSpiritualityManager alloc]initWithSpiritualityManager:dic];
            [weakSelf.mutArrayData removeAllObjects];
            [weakSelf.mutArrayData addObjectsFromArray:PoetryMg.mutDataArray];
            [weakSelf.mutAllOriginalArrayData removeAllObjects];
            [weakSelf.mutAllOriginalArrayData setArray:PoetryMg.historyArrayData];
            //COUNT_num
            NSInteger numberA =  self.mutArrayData.count / 31;
            NSInteger numberB =  self.mutArrayData.count % 31;
            if (numberB == 0) {
                self.numberPage = numberA;
            }else{
                self.numberPage = numberA+1;
            }
            //播放的一些设置
            NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:weakSelf.mutAllOriginalArrayData];
            NSString * strRow = [NSString stringWithFormat:@"10_%@",self.lastPageNumberRow];
            
            if ([distinguishValue isEqualToString:strRow]) {
                LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                _LCPlayer.songs = playlistTest.allSongs;
            }
            [weakSelf.tableViewParticulars reloadData];
            
        }else{
             [self initWithDailyDevotionalDetailsData:page month:month];
        }
    }];
}
#pragma mark - 请求灵修的数据
-(void)initWithDailyDevotionalDetailsData :(NSInteger)page month:(NSString *)month
{
     __weak typeof(self) weakSelf = self;
    [LSZRequestResolutionDic initWithDailyDevotionalDetails:[NSString stringWithFormat:@"%ld",(long)page] type:@"lingxiuSongs" parentId:weakSelf.parentId month:month:^(BOOL isOK, NSString *str, LSZSpiritualityManager * playMg) {
        if (isOK == YES) {
            if (page == 1) {
                [weakSelf.mutArrayData removeAllObjects];
                [weakSelf.mutArrayData addObjectsFromArray:playMg.mutDataArray];
                
                [weakSelf.mutAllOriginalArrayData removeAllObjects];
                [weakSelf.mutAllOriginalArrayData setArray:playMg.historyArrayData];
            }
            else{
                [weakSelf.mutArrayData addObjectsFromArray:playMg.mutDataArray];
                
                [weakSelf.mutAllOriginalArrayData addObjectsFromArray:playMg.historyArrayData];
            }
            
            NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:weakSelf.mutAllOriginalArrayData];
            NSString * strRow = [NSString stringWithFormat:@"10_%@",self.lastPageNumberRow];
            
            if ([distinguishValue isEqualToString:strRow]) {
                LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                _LCPlayer.songs = playlistTest.allSongs;
            }
            [weakSelf.tableViewParticulars reloadData];
        }else{
            [self initAddString:str];
        }
    }];
}
#pragma mark - 首页音频视频歌手_______请求和缓存________________
-(void)ViewTheDataCacheForDetailsOfTheHomeAudio :(NSInteger)page
{
    __weak typeof(self) weakSelf = self;
    if ([self.type isEqualToString:@"zhuanji"]) {
        self.type = @"zhuanjilist";
    }
    if ([self.type isEqualToString:@"geshou"]) {
        self.type = @"geshoulist";
    }
    NSString * str = [NSString stringWithFormat:@"%@_%@_%@",shouye_yinpin,self.type,self.parentId];
    [LSZCacheHandling initWithfindPlist:str :^(BOOL isOk, NSDictionary * dic) {
        if (isOk == YES) {
            LSZSpecificTypePlayManager * MG = [[LSZSpecificTypePlayManager alloc]initWithSpecificTypePlayManager:dic strLastImageView:self.strLastImageView];
            [weakSelf.mutArrayData removeAllObjects];
            [weakSelf.mutArrayData addObjectsFromArray:MG.mutDataArray];
            
            [weakSelf.mutAllOriginalArrayData removeAllObjects];
            [weakSelf.mutAllOriginalArrayData setArray:MG.historyArrayData];
            NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
            for (NSInteger i = 0; i < weakSelf.mutAllOriginalArrayData.count; i++) {
                LSZSpecificTypePlayMg *audioMg = [LSZSpecificTypePlayMg yy_modelWithJSON:weakSelf.mutAllOriginalArrayData[i]];
                audioMg.image = weakSelf.strLastImageView;
                NSDictionary *json = [audioMg yy_modelToJSONObject];
                [mutableArray addObject:json];
            }//添加专辑图片
            
            NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:weakSelf.mutAllOriginalArrayData];
            
            NSString * strRow = [NSString stringWithFormat:@"11_%@_%@",self.lastSection,self.lastPageNumberRow];
            
            if ([distinguishValue isEqualToString:strRow]) {
                LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                _LCPlayer.songs = playlistTest.allSongs;
            }
            
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [weakSelf.tableViewParticulars reloadData];
            }];
        }else{
            [self initWithDatWithPages:page];
        }
    }];
}
#pragma mark - 首页音频请求数据
-(void)initWithDatWithPages :(NSInteger)page
{
    if ([self.type isEqualToString:@"zhuanji"]) {
         self.type = @"zhuanjilist";
    }
    if ([self.type isEqualToString:@"geshou"]) {
        self.type = @"geshoulist";
    }
     __weak typeof(self) weakSelf = self;
    [LSZRequestResolutionDic initWithAlbumDetailsPage:[NSString stringWithFormat:@"%ld",(long)page] type:weakSelf.type parentId:weakSelf.parentId strLastImageView:self.strLastImageView :^(BOOL isOK, NSString * Str, LSZSpecificTypePlayManager * sudioManager) {
        if (isOK == YES) {
            if (page == 1) {
                [weakSelf.mutArrayData removeAllObjects];
                [weakSelf.mutArrayData addObjectsFromArray:sudioManager.mutDataArray];
                
                [weakSelf.mutAllOriginalArrayData removeAllObjects];
                [weakSelf.mutAllOriginalArrayData setArray:sudioManager.historyArrayData];
            }
            else{
                [weakSelf.mutArrayData addObjectsFromArray:sudioManager.mutDataArray];
                [weakSelf.mutAllOriginalArrayData addObjectsFromArray:sudioManager.historyArrayData];

            }
            NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
            for (NSInteger i = 0; i < weakSelf.mutAllOriginalArrayData.count; i++) {
                LSZSpecificTypePlayMg *audioMg = [LSZSpecificTypePlayMg yy_modelWithJSON:weakSelf.mutAllOriginalArrayData[i]];
                audioMg.image = weakSelf.strLastImageView;
                NSDictionary *json = [audioMg yy_modelToJSONObject];
                [mutableArray addObject:json];
            }//添加专辑图片

            NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:weakSelf.mutAllOriginalArrayData];
            
            NSString * strRow = [NSString stringWithFormat:@"11_%@_%@",self.lastSection,self.lastPageNumberRow];
            
            if ([distinguishValue isEqualToString:strRow]) {
                LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                _LCPlayer.songs = playlistTest.allSongs;
            }
             
            [weakSelf.tableViewParticulars reloadData];
        }else{
            [self initAddString:Str];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creareAVPlay];
//    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
//    _LCPlayer.songs = playlistTest.allSongs;
//    if (_LCPlayer.songs != nil) {// && _LCPlayer.currentTime == 0
//        [_LCPlayer playAtIndex:self.numberRow isSelectPlay:YES];
//    }
    self.numberRow = -1;//默认点击的是-1行
    self.mutArrayData = [[NSMutableArray alloc]init];
    // 设置导航控制器的代理为self
    self.navigationController.delegate = self;
    self.view.backgroundColor = [UIColor whiteColor];
    [self setUiTop];
}
-(void)clickButBack
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - UI
-(void)setUiTop
{
    UIImageView *backgroundView = [[UIImageView alloc] init];
    [backgroundView sd_setImageWithURL:[NSURL URLWithString:self.strTopImageView] placeholderImage:[UIImage imageNamed:@"devotion_bannerB"]];
    backgroundView.frame = CGRectMake(0, 0, ScreenWidth, 180);
    backgroundView.contentMode = UIViewContentModeScaleAspectFill;
    backgroundView.userInteractionEnabled = YES;
    [self.view addSubview:backgroundView];
//添加毛玻璃效果
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = CGRectMake(0, 0, backgroundView.frame.size.width*1.0, backgroundView.frame.size.height);
    effectView.alpha = 0.7;
    [backgroundView addSubview:effectView];
 
    UIButton * buttonBack = [[UIButton alloc]initWithFrame:CGRectMake(0, 0 , 70, NAVIGATION_BAR_HEIGHT)];
    [buttonBack addTarget:self action:@selector(clickButBack) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:buttonBack];
//
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, NAVIGATION_BAR_HEIGHT-10-20 , 12, 20)];
    imageView.image = [UIImage imageNamed:@"home_nav_button_back"];
    [self.view addSubview:imageView];
    //标题
    UILabel * labelTitle = [[UILabel alloc]initWithFrame:CGRectMake((ScreenWidth-220)/2, NAVIGATION_BAR_HEIGHT-34, 220, 20)];
    labelTitle.font = FONT_18;
    labelTitle.textColor = [UIColor whiteColor];
    labelTitle.text = [NSString stringWithFormat:@"%@",self.titleStr];
    labelTitle.textAlignment = NSTextAlignmentCenter;
    [backgroundView addSubview:labelTitle];
    //从灵修那过来的
    if ([self.typeComeWhere isEqualToString:@"2"]) {
      
        NSString * month = [LSZSpecialPackaging GetTheCurrentMonth];
        int a = 0;
        for (int i = 0; i<self.date3Array.count; i++) {
            NSString * string = [NSString stringWithFormat:@"%@",self.date3Array[i]];
            if ([string isEqualToString:month]) {
                a = 1;
            }
        }
        if (a == 0) {
           month = [NSString stringWithFormat:@"%@",self.date3Array[0]];
        }

        self.labelMonth = [[UILabel alloc]initWithFrame:CGRectMake((ScreenWidth-220)/2,CGRectGetMaxY(labelTitle.frame)+7,labelTitle.frame.size.width, 15)];
        self.labelMonth.textAlignment = NSTextAlignmentCenter;
        self.labelMonth.textColor = [UIColor whiteColor];
        self.labelMonth.font = FONT_12;
        self.labelMonth.text = [NSString stringWithFormat:@"- %@月 -",month];
        [backgroundView addSubview:self.labelMonth];
        
        UIButton * buttonChooseMoneth = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-35, NAVIGATION_BAR_HEIGHT-10-20, 22, 21)];
        [buttonChooseMoneth setImage:[UIImage imageNamed:@"首页_音频播放_月份选择"] forState:UIControlStateNormal];
        [buttonChooseMoneth addTarget:self action:@selector(clickButChoose) forControlEvents:UIControlEventTouchUpInside];
        [backgroundView addSubview:buttonChooseMoneth];
        
        UILabel * labelUpdate = [[UILabel alloc]initWithFrame:CGRectMake(0, backgroundView.frame.size.height-30, ScreenWidth, 14)];
        labelUpdate.textColor = [UIColor whiteColor];
        labelUpdate.font = FONT_13;
        labelUpdate.text = [NSString stringWithFormat:@"更新至%@期",self.Update];
        labelUpdate.textAlignment = NSTextAlignmentCenter;
        [backgroundView addSubview:labelUpdate];
    }
    if ([self.typeComeWhere isEqualToString:@"3"]) {
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(20,100, ScreenWidth-40, backgroundView.frame.size.height-120)];
        label.font = FONT_14;
        label.text = self.contentStr;
        label.textColor = [UIColor whiteColor];
        label.numberOfLines = 0;
        [backgroundView addSubview:label];
    }
    [self.tableViewParticulars registerClass:[LSZRandombroadcastHeaderCell class] forHeaderFooterViewReuseIdentifier:@"LSZRandombroadcastHeaderCell"];
    [self.tableViewParticulars registerClass:[LSZPlayImageTableViewCell class] forCellReuseIdentifier:@"LSZPlayImageTableViewCell"];
    [self.tableViewParticulars registerClass:[LSZPalyShareTableViewCell class] forCellReuseIdentifier:@"LSZPalyShareTableViewCell"];
#pragma mark - 上下拉  加载数据
    self.tableViewParticulars.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        self.numberPage = 1;
        //首页音频视频歌手
        if([self.typeComeWhere isEqualToString:@"1"]){
            [self ViewTheDataCacheForDetailsOfTheHomeAudio:self.numberPage];
        }
        //诗歌的分类
        if([self.typeComeWhere isEqualToString:@"3"]){
            [self ViewTheDataCacheForDetailsOfTheHymnPoem:self.numberPage];
        }
        if([self.typeComeWhere isEqualToString:@"2"]){
            [self QueryDataDailyDevotionalDetails:self.numberPage month:self.chooseMonth];
        }
        [self.tableViewParticulars.mj_header endRefreshing];
    }];
    
    // 上拉刷新
    self.tableViewParticulars.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        self.numberPage ++;
        //首页音频视频歌手
        if([self.typeComeWhere isEqualToString:@"1"]){
            [self initWithDatWithPages:self.numberPage];
        }
        //诗歌的分类
        if([self.typeComeWhere isEqualToString:@"3"]){
            [self initWithClassificationPoetry:self.numberPage];
        }
        if([self.typeComeWhere isEqualToString:@"2"]){
            [self initWithDailyDevotionalDetailsData:self.numberPage month:self.chooseMonth];
        }
        [self.tableViewParticulars.mj_footer endRefreshing];
    }];
    self.viewSharePopover.hidden = YES;
    self.viewLow.hidden = YES;
    self.butCancel.hidden = YES;
    [LCFloatingWindow sharedInstance].hidden = NO;
}
#pragma mark - 分享弹出来的view
-(UIView *)viewSharePopover
{
    if(_viewSharePopover == nil){
        [LSZSpecialPackaging initAlterView:self.view :^(UIView * viewBack,UIView * viewLow, UIButton * buttonFriends, UIButton * buttonFriendsCircle, UIButton * buttonDownload, UIButton * butCancel) {
            _viewSharePopover = viewBack;
            [self.view bringSubviewToFront:_viewSharePopover];
            [self.tableViewParticulars bringSubviewToFront:_viewSharePopover];

            self.viewLow = viewLow;
            [self.view bringSubviewToFront:self.viewLow];
            [self.tableViewParticulars bringSubviewToFront:self.viewLow];
            
            self.butCancel = butCancel;
            [self.view bringSubviewToFront:self.butCancel];
            [self.tableViewParticulars bringSubviewToFront:self.butCancel];
 
            [buttonFriends addTarget:self action:@selector(clickShareWeiXin) forControlEvents:UIControlEventTouchUpInside];
            [buttonFriendsCircle addTarget:self action:@selector(clickShareWeiXinFriendsCircle) forControlEvents:UIControlEventTouchUpInside];
            [buttonDownload addTarget:self action:@selector(clickDoenload) forControlEvents:UIControlEventTouchUpInside];
            [butCancel addTarget:self action:@selector(clickButCancel) forControlEvents:UIControlEventTouchUpInside];
        }];
    }
    return _viewSharePopover;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
     if([self.typeComeWhere isEqualToString:@"1"]||[self.typeComeWhere isEqualToString:@"3"]){
         return 40;
     }else{
         return 0.001;
     }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutArrayData.count;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if([self.typeComeWhere isEqualToString:@"1"]||[self.typeComeWhere isEqualToString:@"3"]){
        LSZRandombroadcastHeaderCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZRandombroadcastHeaderCell"];
        if (!cell) {
            cell = [[LSZRandombroadcastHeaderCell alloc]initWithReuseIdentifier:@"LSZRandombroadcastHeaderCell"];
        }
        UITapGestureRecognizer * singleTapimageView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickButRandom:)];
        [cell.imageViewPlay addGestureRecognizer:singleTapimageView];
        
        UITapGestureRecognizer * singleTaplabel = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickButRandom:)];
        [cell.label addGestureRecognizer:singleTaplabel];
        
        [cell.butPaly addTarget:self action:@selector(clickButRandom:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }else{
        UITableViewHeaderFooterView * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"cell"];
        }
        return cell;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([self.typeComeWhere isEqualToString:@"1"]||[self.typeComeWhere isEqualToString:@"3"])
    {
        LSZPalyShareTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZPalyShareTableViewCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[LSZPalyShareTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LSZPalyShareTableViewCell"];
        }
        if ([self.typeComeWhere isEqualToString:@"1"]) {
            LSZSpecificTypePlayMg * audioMg = nil;
            audioMg = self.mutArrayData[indexPath.row];
            cell.lableTitle.text = [NSString stringWithFormat:@"%@",audioMg.title];
            cell.labelIntroduce.text = [NSString stringWithFormat:@"%@",audioMg.album];
            if (_LCPlayer.selectedIndex == indexPath.row && [[LCHistoryDataManager loadOneSongsData] isEqualToString:cell.lableTitle.text] && [cell.labelIntroduce.text isEqualToString:_LCPlayer.playingSong.album]) {
                [cell clickOnThisSongToPlayPalyShare:YES];
                lastClickRow = indexPath.row;
            }else{
                [cell clickOnThisSongToPlayPalyShare:NO];
            }        }
        //从诗歌_分类 进来的
        if ([self.typeComeWhere isEqualToString:@"3"]) {
            LSZSpecificTypePlayMg * audioMg = nil;
            audioMg = self.mutArrayData[indexPath.row];
            cell.lableTitle.text = [NSString stringWithFormat:@"%@",audioMg.title];
            if ([audioMg.album isEqualToString:@""]) {
                cell.labelIntroduce.text = [NSString stringWithFormat:@"%@",audioMg.singerName];
                if (_LCPlayer.selectedIndex == indexPath.row && [[LCHistoryDataManager loadOneSongsData] isEqualToString:cell.lableTitle.text] && [cell.labelIntroduce.text isEqualToString:_LCPlayer.playingSong.singerName]) {
                    [cell clickOnThisSongToPlayPalyShare:YES];
                    lastClickRow = indexPath.row;
                }else{
                    [cell clickOnThisSongToPlayPalyShare:NO];
                }
            }else{
                cell.labelIntroduce.text = [NSString stringWithFormat:@"%@",audioMg.album];
                if (_LCPlayer.selectedIndex == indexPath.row && [[LCHistoryDataManager loadOneSongsData] isEqualToString:cell.lableTitle.text] && [cell.labelIntroduce.text isEqualToString:_LCPlayer.playingSong.album]) {
                    [cell clickOnThisSongToPlayPalyShare:YES];
                    lastClickRow = indexPath.row;
                }else{
                    [cell clickOnThisSongToPlayPalyShare:NO];
                }
            }

        }
      // self.shareImage
//        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickButShare)];
//        [cell.shareImage addGestureRecognizer:tap];
  
        cell.butShare.tag = indexPath.row;
        [cell.butShare addTarget:self action:@selector(clickButShare:) forControlEvents:UIControlEventTouchUpInside];

         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if ([self.typeComeWhere isEqualToString:@"2"]){
        LSZPlayImageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZPlayImageTableViewCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[LSZPlayImageTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LSZPlayImageTableViewCell"];
        }
        LSZSpiritualityMg * SpiritualityMg = nil;
        SpiritualityMg = self.mutArrayData[indexPath.row];
        
        cell.labelTime.text = [NSString stringWithFormat:@"%@",SpiritualityMg.addtime];
        cell.labelName.text = [NSString stringWithFormat:@"%@",SpiritualityMg.title];
        NSLog(@"%@",SpiritualityMg.duration);
        cell.labelHowLong.text = [NSString stringWithFormat:@"%@",SpiritualityMg.duration];

     
        NSLog(@"%@>>>>>>>>%@",_LCPlayer.playingSong.id,SpiritualityMg.id_id);
        NSLog(@"%@>>>>>>>>%@",_LCPlayer.playingSong.album,SpiritualityMg.singerName);
        if (_LCPlayer.selectedIndex == indexPath.row && [_LCPlayer.playingSong.album isEqualToString:SpiritualityMg.singerName]&&[_LCPlayer.playingSong.id isEqualToString:SpiritualityMg.id_id]) {
            [cell clickOnThisSongToPlayPlayImageTableViewCell:YES];
            lastClickRow = indexPath.row;
        }else{
            [cell clickOnThisSongToPlayPlayImageTableViewCell:NO];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
    else{
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        }
        return cell;
    }
}
#pragma mark - 切换歌
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
    _LCPlayer.songs = playlistTest.allSongs;
 
    //从音频专辑歌手是1有随机播放区头  每日灵修的地方进来的是2   从赞美诗的分类过来的是3
    if([self.typeComeWhere isEqualToString:@"1"]){
        NSString * strRow = [NSString stringWithFormat:@"11_%@_%@",self.lastSection,self.lastPageNumberRow];
        _LCPlayer.valueDistinguish = strRow;    
    }
    
    if([self.typeComeWhere isEqualToString:@"2"]){
        NSString * strRow = [NSString stringWithFormat:@"10_%@",self.lastPageNumberRow];
        _LCPlayer.valueDistinguish = strRow;
    }
    if([self.typeComeWhere isEqualToString:@"3"]){
        NSString * strRow = [NSString stringWithFormat:@"2_2_%@",self.lastPageNumberRow];
        _LCPlayer.valueDistinguish = strRow;
    }
    [_LCPlayer playAtIndex:indexPath.row isSelectPlay:YES];//播放歌曲
    NSInteger lastRow = lastClickRow;
    lastClickRow = (NSInteger)indexPath.row;
    if (lastRow <0) {
    }else{
        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:lastRow inSection:0];
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    }
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}
#pragma mark - 点击随机播放的按钮
-(void)clickButRandom:(UIButton *)but
{
    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
    _LCPlayer.songs = playlistTest.allSongs;
    _LCPlayer.listStatus = LCMusicListStatusAllCycle; 
    [_LCPlayer playAtIndex:0 isSelectPlay:YES];
}
#pragma mark - 选择月份
-(void)clickButChoose
{
    NSMutableArray * mutArrayDate = [[NSMutableArray alloc]init];
    for (int i = 0; i<self.date3Array.count; i++) {
        NSString * string = [[NSString alloc]initWithFormat:@"%@月",self.date3Array[i]];
        [mutArrayDate addObject:string];
    }
    DLPickerView * pickerView = [[DLPickerView alloc] initWithDataSource:mutArrayDate
                                                        withSelectedItem:nil
                                                       withSelectedBlock:^(id selectedItem)
                                 {
                                     self.labelMonth.text = [NSString stringWithFormat:@"- %@ -",selectedItem];
                                     self.chooseMonth = [NSString stringWithFormat:@"%@",selectedItem];
                                     [self QueryDataDailyDevotionalDetails:self.numberPage month:self.chooseMonth];
                                 }];
    [pickerView show];
}
#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
     [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
#pragma mark - 点击的哪一行的要分享
-(void)clickButShare :(UIButton *)but
{
    self.shareAndDownloadNumberRow = but.tag;
    
    if(self.numberRow == but.tag){
        self.viewSharePopover.hidden = YES;
        self.viewLow.hidden = YES;
        self.butCancel.hidden = YES;
        [LCFloatingWindow sharedInstance].hidden = NO;
        self.numberRow = -1;
    }else{
        self.viewSharePopover.hidden = NO;
        self.viewLow.hidden = NO;
        self.butCancel.hidden = NO;
        [LCFloatingWindow sharedInstance].hidden = YES;
        self.numberRow = but.tag;
    }
    //从诗歌分类进来的tag 从10000开始
    //    if (self.viewSharePopover.hidden == YES) {
    //        self.viewSharePopover.hidden = NO;
    //    }else{
    //        self.viewSharePopover.hidden = YES;
    //    }
}
#pragma mark - 点击微信分享好友
-(void)clickShareWeiXin
{
    NSString * strUrl = [[NSString alloc]init];
    NSString * strTitle = [[NSString alloc]init];
    LSZSpecificTypePlayMg * audioMg = nil;
    audioMg = self.mutArrayData[self.shareAndDownloadNumberRow];
    strUrl = audioMg.fileUrl;
    strTitle = audioMg.title;    NSArray* imageArray = @[[UIImage imageNamed:@"placeholder"]];
    [LSZSpecialPackaging shareWXWithViewController:self imageArray:imageArray url:strUrl title:strTitle contentMessage:@"" type:0];
    [self clickButCancel];
}
#pragma mark - 点击微信分享朋友圈
-(void)clickShareWeiXinFriendsCircle
{
    NSLog(@"点击微信分享朋友圈");
    NSString * strUrl = [[NSString alloc]init];
    NSString * strTitle = [[NSString alloc]init];
    LSZSpecificTypePlayMg * audioMg = nil;
    audioMg = self.mutArrayData[self.shareAndDownloadNumberRow];
    strUrl = audioMg.fileUrl;
    strTitle = audioMg.title;
    NSArray* imageArray = @[[UIImage imageNamed:@"placeholder"]];
    [LSZSpecialPackaging shareWXWithViewController:self imageArray:imageArray url:strUrl title:strTitle contentMessage:@"" type:1];
    [self clickButCancel];
}
#pragma mark - 点击下载的按钮
-(void)clickDoenload
{
//    if ([self.typeComeWhere isEqualToString:@"1"]) {
//    }
    LSZSpecificTypePlayMg * audioMg = nil;
    audioMg = self.mutArrayData[self.shareAndDownloadNumberRow];
    NSDictionary *json = [audioMg yy_modelToJSONObject];
    JKSongsMessStatus *song = [JKSongsMessStatus yy_modelWithJSON:json];
    [kNetworkTool downloadSongWithUrl:song];
    NSLog(@"点击下载的按钮的点击事件");
    [self clickButCancel];
}
#pragma mark - 分享或者下载的view   下落
-(void)clickButCancel
{
    _viewSharePopover.hidden = YES;
    self.viewLow.hidden = YES;
    self.butCancel.hidden = YES;
    [LCFloatingWindow sharedInstance].hidden = NO;
    self.numberRow = -1;
}
-(UITableView *)tableViewParticulars
{
    if (_tableViewParticulars == nil) {
        _tableViewParticulars = [[UITableView alloc]initWithFrame:CGRectMake(0, 180, ScreenWidth, ScreenHeight-180-15) style:UITableViewStylePlain];
        if(iPhoneX){
            _tableViewParticulars.frame = CGRectMake(0, 180, ScreenWidth, ScreenHeight-180-50);
        }
        _tableViewParticulars.delegate = self;
        _tableViewParticulars.dataSource = self;
        //添加以下代码关闭估算行高
        _tableViewParticulars.estimatedRowHeight = 0;
        _tableViewParticulars.estimatedSectionHeaderHeight = 0;
        _tableViewParticulars.estimatedSectionFooterHeight = 0;
        [self.view addSubview:_tableViewParticulars];
    }
    return _tableViewParticulars;
}

@end
